package interfaces.clients.connection;

import interfaces.clients.authorization.AuthorizationData;
import interfaces.clients.dispatcher.commands.BaseCommand;
import interfaces.clients.dispatcher.commands.CommandReader;
import interfaces.clients.dispatcher.commands.NoClassCorrectableDebugException;
import interfaces.clients.dispatcher.commands.ReadCorrectableException;

import java.io.ObjectInputStream;

/**
 * A class representing a single user commands.<br>
 * <br>
 *
 * @author Mihail A. Muhin
 */
public class Request {
	private AuthorizationData adata = null;

	private BaseCommand cdata = null;

	public Request() {
	}

	public Request(AuthorizationData adata, BaseCommand cdata) {
		this.adata = adata;
		this.cdata = cdata;
	}

	public BaseCommand getCdata() {
		return cdata;
	}

	public AuthorizationData getAdata() {
		return adata;
	}

	public void read(ObjectInputStream ois) throws ReadCorrectableException, NoClassCorrectableDebugException,
			interfaces.clients.dispatcher.commands.ReadCorrectableException {
		adata = new AuthorizationData();
		try {
			adata.read(ois);
		} catch (ReadCorrectableException e) {
			throw new ReadCorrectableException(e.getMessage());
		} catch (NoClassCorrectableDebugException e) {
			throw new NoClassCorrectableDebugException(e.getMessage(), e);
		}
		cdata = CommandReader.read(ois);
	}
}
